package com.stream.utils;

import org.apache.commons.beanutils.ConvertUtils;

import java.util.HashMap;
import java.util.Map;

/**
 *
 * 数字类型转换
 * Created by yebaokang on 2017/5/22.
 */
public class NumberConversion {

    public static Integer convertInt(Object value) {
        return convertInt(value, 0);
    }
    public static Integer convertInt(Object value, Integer nullDefault) {
        if (value == null) {
            return nullDefault;
        }

        if (value instanceof Integer) {
            return (Integer) value;
        }

        if (value instanceof String) {
            String data = null;
                data = (String) value;
            try {
                return Integer.parseInt(data);
            } catch (NumberFormatException e) {
//                e.printStackTrace();
            }
        }

        return nullDefault;
    }

}
